package org.zjvis.datascience.common.dto;

import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.annotation.JsonFormat;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;
import org.springframework.util.StringUtils;
import org.zjvis.datascience.common.util.DozerUtil;
import org.zjvis.datascience.common.vo.ModelLocalVO;

@Data
@SuperBuilder
@AllArgsConstructor
@NoArgsConstructor
public class ModelLocalDTO extends BaseDTO {

    private Long id;//主键

    private Long modelId;//模型id，不同版本的模型id一样，id不一样

    private Long userId;

    private Long projectId;

    private Long uid;

    private int type;//算法或模型

    private String name;//模型名称

    private String relatedAlgo;//关联算法名称

    private String owner;//作者

    private String profile;//头像信息

    private String workplace;//工作单位

    private String icon;//图标

    private String cover;//封面图片

    private boolean publicModel;//是否公开代码或模型

    private boolean publicData;//是否公开数据

    private String field;//领域

    private String summary;//摘要

    private String keyword;//关键字

    private String modelDesc;//模型详细说明

    private Long star;//收藏数

    private Long watch;//点击量

    private Long download;//下载量

    private String version;//版本

    private int numVersion;//有几个版本

    private boolean topVersion = true;//是否是最新版本

    private String params;//参数

    private String metric;//指标

    private String config;//配置

    private int status;//审核状态

    private String comment;//审核评论

    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime publicTime;//发布时间

    private String resource;//相关资料

    private String reference;//参考文献

    private String instruction;//使用说明

    private boolean trainable;//是否可训练

    private int installStatus;//安装状态

    private int trainStatus;//训练状态

    private String otherInfo;//其他信息

    private String inferenceTable;//输入源

    private int inPanel;//是否在panel（1 for models in panel(not in folder); 2 for models in folder）

    private Long folderId;//文件夹id

    private Long runTime;//整体运行时间

    private Long datasetRecords;//数据集数据量

    private String progressId;//pid/applicaiton ID

    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss")
    private LocalDateTime trainTime;

    public ModelLocalVO view() {
        ModelLocalVO vo = DozerUtil.mapper(this, ModelLocalVO.class);
        if (StringUtils.isEmpty(this.getParams())){
            vo.setParamsJson(new JSONObject(true));
        } else {
            vo.setParamsJson(JSONObject.parseObject(this.getParams()));
        }
        if (StringUtils.isEmpty(this.getMetric())){
            vo.setMetricJson(new JSONObject(true));
        } else {
            vo.setMetricJson(JSONObject.parseObject(this.getMetric()));
        }
        if (StringUtils.isEmpty(this.getConfig())){
            vo.setConfigJson(new JSONObject(true));
        } else {
            vo.setConfigJson(JSONObject.parseObject(this.getConfig()));
        }
        if (StringUtils.isEmpty(this.getOtherInfo())){
            vo.setOtherInfoJson(new JSONObject(true));
        } else {
            vo.setOtherInfoJson(JSONObject.parseObject(this.getOtherInfo()));
        }
        return vo;
    }

}
